[#include "/includes/_layout.html"/]
<script type="text/javascript">
var qname = "";
var addPrizeDailog = null;
	$(document).ready(function() {
	    $("#myPrizeQueryBtn").click(function(){
	    	qname = $("#q_pond_txt").val() == "输入奖品名称" ? "" : $("#q_pond_txt").val();
	    	searchPrizes();
	    });
	    $('button[id^=type_]').click(function(){
        	var me = $(this);
        	addPrizeDailog = BootstrapDialog.show({
				size: BootstrapDialog.SIZE_WIDE,
				title: me.text(),
	            message: $('<div></div>').load('${webctx}/prize/type/'+me.attr("code")+"/?typeId="+me.attr("typeid"))
	        });
        });
	});
	var pageClick = function(pageNo) {
		searchPrizes(pageNo);
	}
	var searchPrizes = function(currPage){
		var params = {};
		//其他查询条件
		if(currPage){
			params.page = currPage;
		}
		params.qname = qname;
		params.type = $("#p_status_sel").val();
		$("#mainTable").mask("加载中...");
		var url = obz.ctx + "/prize/list";
		obz.ajaxJson(url, params, function(resp){
			var result = resp.data;
			$(".prizeLotGrid").empty();
			if(currPage){
				$("#pager").pager({ pagenumber:currPage, recordcount:result.totalRow, pagesize:result.pageSize, recordtext:'共 {0} 页, {1} 条记录', buttonClickCallback: pageClick });
			}else{
				$("#pager").pager({ recordcount:result.totalRow, pagesize:result.pageSize, recordtext:'共 {0} 页, {1} 条记录', buttonClickCallback: pageClick });	
			}
			var dataList = result.list;
			if(dataList.length>0){
				for(var i=0;i<dataList.length;i++){
					var _row = dataList[i];
					var trHtml = obz.dataTemplate4obj($("#prize_table_tr_tpl").html(), _row);
					$(".prizeLotGrid").append(trHtml);
				}
				//初始化checkbox点击事件
				TBatch.checkCheckbox();
				TBatch.initCheckboxClick();
				TBatch.initOptEvent(PrizeOpt.init());
			}else {
				$(".prizeLotGrid").append($("#prize_table_noresult_tr_tpl").html());
			}
			$("#mainTable").unmask();
		});
	}
	//初始化table
    searchPrizes();
	//=============================表格操作事件开始=============================================
	var PrizeOpt = {
		sel : function(param){
			var id = param[1];
			//selectedPond(id, $("#prizeName_"+id).text());
			obz.doSelectPrzie(id, $("#prizeName_"+id).text());
			if(selectDialog != null) selectDialog.close();
		},
		init : function(){
			var optArray = new Array();
			optArray.push(this.sel);
			return optArray;
		}
	}	
	//=============================表格操作事件结束=============================================
		
	function closeSelectDialog(){
		if(selectDialog != null) selectDialog.close();
	}
</script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg">
<div class="panel panel-default main-bg">
	<!-- <div class="panel-heading">
		<h2><strong>添加奖品</strong></h2>
	</div> -->
	<div class="panel-body">
		[#list prizeTypes as type ]
			<button id="type_${type.id}" type="button" class="btn btn-info" typeid="${type.id }" code="${type.typeCode }">${type.typeName }</button>
		[/#list]
	</div>
</div>
<div id="tableList">
	<table class="table-striped">
		<tr>
			<td colspan="3" style="text-align: left;">&nbsp;&nbsp;
				<input type="text" name="q_pond_txt" id="q_pond_txt" class="input-text"
				style="width:190px; color:#DFDFDF" value="输入奖品名称" 
				onfocus="if(this.value=='输入奖品名称'){this.value=''};this.style.color='black';" 
				onblur="if(this.value==''||this.value=='输入奖品名称'){this.value='输入奖品名称';this.style.color='#DFDFDF';}"/>
				<select id="p_status_sel" style="width: 102px">
					<option value="" selected="selected">全部</option>
					[#list prizeTypes as type ]
						<option value="${type.id }">${type.typeName }</option>
					[/#list]
				</select> 
				<button id="myPrizeQueryBtn" class="btn btn-success">查询</button>
			</td>
		</tr>
	</table>

	<div id="prizeToolsbar" class="panel-body">
		<div id="pager" class="jqpager" style="margin-bottom: 1px;"></div>		
	</div>
	<table class="table table-striped table-bordered bootstrap-datatable datatable" id="mainTable" border="0">
		<thead>
			<tr>
				<th>
					<input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/>
				</th>
				<th>
					<span style="vertical-align: middle;">奖品名称</span>
				</th>
				<th>奖品类型</th>
				<th>状态</th>
				<th>奖品总数</th>
				<th>已兑换数量</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody class="prizeLotGrid">
		</tbody>
	</table>
</div>

<div class="panel-footer" align="center">
 	 <button onclick="closeSelectDialog()" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i>关闭</button>
</div>

<!-- html 模板文件 -->
<script type="text/template" id="prize_table_tr_tpl">
<tr class="package">
			<td valign="middle">
				<input type="checkbox" class="commchk" id="checkbox_{id}" style="margin-right: 4px; vertical-align: middle;"/>
			</td>
			<td>
				<span id="prizeName_{id}">{prizeName}</span>
			</td>
			<td>
				{prizeType}
			</td>
			<td>
				{status}
			</td>
			<td>
				<span class="isArrive">
				{publishCount}
				</span>
			</td>
			<td>{hadOutCount}</td>
			<td style="white-space: normal">
				<span>
					{startDate}
				</span>
			</td>
			<td>
				<span>
					{endDate}
				</span>
			</td>
			<td>
				&nbsp;<a id="select_{id}" href="javascript:void(0)" class="btn btn-success">选择</a>
			</td>
		</tr>		
</script>

<script type="text/template" id="prize_table_noresult_tr_tpl">
<tr class="package">
			<td nowrap="nowrap" class="center" colspan="9">
				还没有奖品
			</td>
		</tr>
</script>
</body>
</html>	
	
